package com.ruoyi.web.controller.customer;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.mapper.SysVoiceMapper;
import com.ruoyi.web.dto.LTTSDto;
import com.ruoyi.web.dto.SysVioceDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysVoice;
import com.ruoyi.system.service.ISysVoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数字人音色Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/system/SysVoice")
@Api(tags = "数字人音色")
public class SysVoiceController extends BaseController
{
    @Autowired
    private ISysVoiceService sysVoiceService;
    @Autowired
    private SysVoiceMapper sysVoiceMapper;
    /**
     * 查询数字人音色列表
     */
//    @PreAuthorize("@ss.hasPermi('system:SysVoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVoice sysVoice)
    {
        startPage();
        List<SysVoice> list = sysVoiceService.selectSysVoiceList(sysVoice);
        return getDataTable(list);
    }

    /**
     * 导出数字人音色列表
     */
    @PreAuthorize("@ss.hasPermi('system:SysVoice:export')")
    @Log(title = "数字人音色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVoice sysVoice)
    {
        List<SysVoice> list = sysVoiceService.selectSysVoiceList(sysVoice);
        ExcelUtil<SysVoice> util = new ExcelUtil<SysVoice>(SysVoice.class);
        util.exportExcel(response, list, "数字人音色数据");
    }

    /**
     * 获取数字人音色详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:SysVoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysVoiceService.selectSysVoiceById(id));
    }

    /**
     * 新增数字人音色
     */
    @PreAuthorize("@ss.hasPermi('system:SysVoice:add')")
    @Log(title = "数字人音色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVioceDto sysVoicedto)
    {
        SysVoice sysVoice = new SysVoice();
        BeanUtils.copyProperties(sysVoicedto, sysVoice);
        sysVoice.setRid(Long.parseLong(sysVoicedto.getId()));
        sysVoice.setCreateBy(getUserId().toString());
        sysVoice.setUpdateBy(getUserId().toString());
        sysVoice.setCreateTime(new Date());
        sysVoice.setRemark("1");
        return toAjax(sysVoiceService.insertSysVoice(sysVoice));
    }

    /**
     * 修改数字人音色
     */
    @PreAuthorize("@ss.hasPermi('system:SysVoice:edit')")
    @Log(title = "数字人音色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVoice sysVoice)
    {
        return toAjax(sysVoiceService.updateSysVoice(sysVoice));
    }

    /**
     * 删除数字人音色
     */
    @PreAuthorize("@ss.hasPermi('system:SysVoice:remove')")
    @Log(title = "数字人音色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysVoiceService.deleteSysVoiceByIds(ids));
    }
//    @PreAuthorize("@ss.hasPermi('system:SysVoice:query')")
    @Log(title = "数字人音色推荐获取")
    @PostMapping("recommend")
    @ApiOperation("获取数字人音色推荐列表")
    public List<SysVoice> selectSysVoiceAllRecommend(){
        return sysVoiceMapper.selectSysVoiceAllRecommend();
    }
}
